<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加员工</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
</head>
<body>

<div>
    <div>
        <button type="button" class="layui-btn layui-btn-normal">添加员工</button>
    </div>

</div>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入姓名"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline">
                <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" lay-verify="email" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">出生日期</label>
            <div class="layui-input-inline">
                <input type="text" name="birthday" id="date" lay-verify="date" placeholder="yyyy-MM-dd"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">身份证号</label>
        <div class="layui-input-block">
            <input type="text" name="cardId" lay-verify="identity" placeholder="" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-block">
            <select name="jid" lay-filter="aihao">
                <option value=""></option>
                <option value="1" selected="">高级程序员</option>
                <option value="4">产品经理</option>
                <option value="6">测试经理</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">第一学历</label>
            <div class="layui-input-inline">
                <select name="education">
                    <option value="">请选择学历</option>
                    <option value="本科">本科</option>
                    <option value="专科">专科</option>
                    <option value="专科以下">专科以下</option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">请选择部门</label>
            <div class="layui-input-inline">
                <select name="did" lay-verify="required" lay-search="">
                    <option value="">直接选择</option>
                    <option value="1">信息安全部</option>
                    <option value="5">项目开发部</option>
                    <option value="6">市场营销部</option>
                    <option value="7">软件技术部</option>
                    <option value="8">人力资源部</option>
                    <option value="9">生活服务部</option>

                </select>
            </div>
        </div>


    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" lay-verify="address" autocomplete="off" placeholder="请输入地址"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">单选框</label>
        <div class="layui-input-block">
            <input type="radio" name="gender" value="1" title="男" checked="">
            <input type="radio" name="gender" value="2" title="女">
            <input type="radio" name="sex" value="禁" title="请选择" disabled="">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="layui/layui.js" charset="utf-8"></script>
<script src="js/jquery-1.8.3.min.js" type="text/javascript"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });


        //监听提交
        form.on('submit(demo1)', function (data) {
            console.log(data.field);
            $.ajax({
                url: '/oasys/employee/addEmployee.do',
                data: data.field,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        console.log(data);
                        layer.alert(data.info);
                        // location.reload(); //添加成功后再刷新c
                        window.location.href = 'employee.html'
                    } else {
                        layer.alert("添加失败");
                    }
                }
            });
            return false;
        });


        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
</script>

</body>
</html>